<script type="text/javascript">
	// 初始化
	jQuery(function() {
		create_table_grid();
		query_data();
	});

	function create_table_grid() {
		var sort = jQuery(".data_operate_bar [name='fieldSort']").val();
		gxc.grid.create({
			name : "table_grid",
			url : url_local + "/datacenter/table/grid.do",
			withCheckbox : true,
			withRownum : false,
			stripeRows : false,
			stripeOverRow : false,
			withPagebar : true,
			pageSize : 10,
			renderTo : "#table_grid",
			fieldSort : sort,
			loadDataNow : false,
			columns : [ {
				text : "模式名",
				name : "schema_name"
			}, {
				text : "表名",
				name : "table_name"
			}, {
				text : "表描述",
				name : "label"
			}, {
				text : "操作",
				name : "id",
				width : "160px",
				className : "td_operate",
				align : "center",
				render : renderOperate
			} ]
		});
	}

	function renderOperate(item) {
		var operate = "<a  href='javascript: view_table(\"" + item.id
				+ "\")'>查看详细</a>";
		operate += "<a style='margin-left:5px;' href='javascript: edit_table(\""
				+ item.id + "\")'>编辑</a>";
		operate += "<a style='margin-left:5px;' href='javascript: delete_table(\""
				+ item.id + "\")'>删除</a>";
		return operate;
	}

	function query_data() {
		gxc.grid.table_grid.params = null;
		gxc.grid.table_grid.params = gxc.form.getParams("#frm");
		gxc.grid.table_grid.pageCurrent = 1;
		gxc.grid.table_grid.reload();
	}

	function reload() {
		gxc.grid.table_grid.reload();
	}

	function deleteSelected() {
		var id_array = gxc.grid.table_grid.getSelectedRows().toString();
		if (id_array == "") {
			return;
		}
		jQuery.ajax({
			type : "post",
			url : url_local + "/datacenter/table/deleteBatch.do",
			data : {
				id : id_array
			},
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data, textStatus) {
				if (data.status == "success") {
					gxc.dialog.prompt("成功删除 " + data.data + " 条记录！");
					gxc.grid.table_grid.reload();
				}
			},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function() {
			}
		})
	}

	function view_table(id) {
		window.open(url_local + "/datacenter/table/view.do?id=" + id, "_blank");
	}

	function edit_table(id) {
		window.open(url_local + "/datacenter/table/edit.do?id=" + id, "_blank");
	}

	function delete_table(id) {
		jQuery.ajax({
			type : "post",
			url : url_local + "/datacenter/table/delete.do",
			data : {
				id : id
			},
			dataType : "json",
			beforeSend : function(XMLHttpRequest) {
			},
			success : function(data, textStatus) {
				if (data.status == "success") {
					gxc.dialog.prompt("成功删除 " + data.data + " 条记录！");
					gxc.grid.table_grid.reload();
				}
			},
			complete : function(XMLHttpRequest, textStatus) {
			},
			error : function() {
			}
		});
	}

	function collectTables(database_id) {
		jQuery.ajax({
			type : "post",
			url : url_local + "/datacenter/table/collocetByDatabase.do",
			data : {
				database_id : database_id
			},
			dataType : "json",
			success : function(data, textStatus) {
				if (data.status == "success") {
					gxc.dialog.prompt("成功采集 " + data.data.length + " 条记录！");
					gxc.grid.table_grid.reload();
				}
			}
		});
	}
</script>
